import updateManager from './common/updateManager';
var md5 = require('utils/md5.js');
const isDev = ['develop', 'trial'].includes(wx.getAccountInfoSync().miniProgram.envVersion)
App({
	onLaunch: function () {},
	// onShow: function () {
	//   updateManager();
	//   wx.getSetting({
	//     success(res) {
	//       console.log(res.authSetting);
	//       if (res.authSetting['scope.userLocation'] === true) {
	//         wx.authorize({
	//           scope: 'scope.userLocation',
	//           success(resaut) {
	//             console.log(resaut);
	//             // 用户已经同意授权
	//             wx.getLocation({
	//               type: 'wgs84',
	//               success(reswgs) {
	//                 console.log(reswgs);
	//                 const latitude = reswgs.latitude
	//                 const longitude = reswgs.longitude
	//                 const speed = reswgs.speed
	//                 const accuracy = reswgs.accuracy
	//               }
	//             })
	//           }
	//         })
	//       } else {
	//         wx.showModal({
	//           title: '授权提示',
	//           content: '小程序需要您的微信授权才能使用哦~ 错过授权页面的处理方法：1.删除小程序->重新搜索进入->点击授权按钮。2.请点击确认跳转到设置页开启',
	//           success(res) {
	//             if (res.confirm) {
	//               wx.openSetting({
	//                 success(res) {
	//                   console.log(res.authSetting)
	//                   // res.authSetting = {
	//                   //   "scope.userInfo": true,
	//                   //   "scope.userLocation": true
	//                   // }
	//                 }
	//               })
	//             } else if (res.cancel) {
	//               console.log('用户点击取消')
	//             }
	//           }
	//         })
	//       }
	//     }
	//   })
	// },

	/**
	 * 生成签名
	 */
	getSign(data) {
		// 对数组的值按key排序
		data = this.ksort(data);
		// 生成url的形式
		var params = this.http_build_query(data);
		// 生成sign
		var sign = md5.md5(md5.md5(params + this.globalData.secret) + 'wxd');

		return sign;
	},
	/**
	 * 按照键名对数组升序排序
	 */
	ksort(data) {
		var data_keys = [];

		for (var k in data) {
			data_keys.push(k);
		}

		data_keys = data_keys.sort();

		var new_data = {};

		for (var i in data_keys) {
			new_data[data_keys[i]] = data[data_keys[i]];
		}

		return new_data;
	},
	/**
	 * 生成url的形式
	 */
	http_build_query(obj) {
		// return Object.keys(obj).map(k => encodeURIComponent(k) + '=' + encodeURIComponent(obj[k])).join('&');
		var url_str = '';
		for (var i in obj) {
			url_str += "&" + encodeURIComponent(i) + "=" + encodeURIComponent(obj[i]);
		}

		return url_str.substring(1);
	},
	globalData: {
		isFullSucreen: false,
		nonetwork: false,
		isLogin: false,
		adPopupShow: 0,
		adPopupImg: '',
		adPopupUrl: '',
		adPopupUrlType: 1,
		key: '8fa1cf6bb70b8da3e6b584f7cd72dc6c',
		secret: '7bd8cfce524dd38e302f5a304f7d5c04',
		userInfo: null,
		openid: '',
		b_id: '',
		v_id: '',
		is_advert: 0,
		tel: false,
		code: '',
		session_key: '',
		latitude: '',
		longitude: '',
		business_area: '',
		business_name: '',
		// Baseurl: 'http://dt.com/index.php/home/',
		// BaseImgUrl: 'http://dt.com/public',
		// Baseurl: 'http://dtwxd.com/index.php/home/',
		// BaseImgUrl: 'http://dtwxd.com/public',
		//Baseurl: 'https://dt.lxcx365.com/index.php/home/',
		//BaseImgUrl: 'https://dt.lxcx365.com/public',
		Baseurl: 'https://lxbl.lxcx365.com/index.php/home/',
		BaseImgUrl: 'https://lxbl.lxcx365.com/public',
    baseImgUrl: isDev ? 'http://111.203.231.105:801' : 'https://www.zhulichuxing.com',
    baseApiUrl: isDev ? 'http://111.203.231.105:801' : 'https://www.zhulichuxing.com'
	},
	onShow() {
		wx.onCopyUrl((result) => {
			setTimeout(() => {
				wx.setClipboardData({
					data: "不可复制",
				})
			}, 1000)
		})
	}
});
